using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.VersionControl;
using UnityEngine;



public class BulletPool
{
    private static BulletPool instance = null;
    private Stack<GameObject> bullets = new Stack<GameObject>();
    private Transform bulletPool = GameObject.Find("BulletPool").transform;
    private BulletPool()
    {
        OnInit();
    }

    public static BulletPool GetInstance()
    {
        if (null == instance)
        {
            instance = new BulletPool();
        }
        return instance;
    }

    private void OnInit()
    {
       
        GameObject prefab = Resources.Load<GameObject>("Bullet");
        for (int i = 0; i < 50; i++)
        {
            GameObject go =  GameObject.Instantiate(prefab, bulletPool);
            go.SetActive(false);
            bullets.Push(go);
        }
    }

    public GameObject Spwan(Transform parent, Vector3 pos)
    {
        if (bullets.Count == 0)
        {
            this.OnInit();
        }

        GameObject go = bullets.Pop();
        go.SetActive(true);
        go.transform.parent = parent;
        go.transform.position = pos;
        return go;
    }

    public void DeSpwan(GameObject go)
    {
        bullets.Push(go);
        go.SetActive(false);
        go.transform.parent = bulletPool;
    }
 

  

}
